package com.zmn.oms.third.shunfeng;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.stereotype.Component;

/**
 * 顺丰渠道常量定义类
 *
 * @author xiewenbing
 * @date 2020/12/09
 */
@Component
public class ShunfengConsts {

    /**
     * 渠道名称
     */
    public final static String CHANNEL_NAME = "顺丰安维";

    /**
     * 渠道对接开关
     */
    public static boolean POWER_ON = true;

    /**
     * 合作伙伴编码
     */
    public static String PARTNER_ID = "fop_test";

    /**
     * 生成签名的md5 key
     */
    public static String MD5_KEY = "2Z7YPBNG2CKKBV17";

    /**
     * api url
     */
    public static String API_URL = "https://sfapi.sit.sf-express.com:45273/std/service";

    /**
     * image url
     */
    public static String IMAGE_URL = "http://scs-api-gw.intsit.sfdc.com.cn:1080/hinplusService/routerPic/imageUpload";

    /**
     * 图片上传的Client Code
     */
    public static String CLIENT_CODE = "FOP_JDD516";

    /**
     * 图片生成签名的md5 key
     */
    public static String IMAGE_MD5_KEY = "4PqXaZMkyHHZpbN9";

    /**
     * 订单状态 - 新增/修改
     */
    public final static String ORDER_STATUS_UPDATE = "1";

    /**
     * 订单状态 - 取消
     */
    public final static String ORDER_STATUS_CANCEL = "2";

    /**
     * 服务类型 - 上门安装
     */
    public final static String SERVICE_TYPE_INSTALL = "1";

    /**
     * 服务类型 - 提货+安装
     */
    public final static String SERVICE_TYPE_PICKUP_AND_INSTALL = "2";

    /**
     * 图片回传类型 - 订单完成
     */
    public final static int IMAGE_TYPE_SERVICE_COMPLETE = 68;

    /**
     * 图片回传类型 - 安装异常
     */
    public final static int IMAGE_TYPE_INSTALL_FAILED = 13;

    /**
     * 接口服务代码 - 订单消息推送
     */
    public final static String SERVICE_CODE_PUSH_ORDER = "FOP_PUSH_FIS_ORDER";

    /**
     * 接口服务代码 - 到货通知推送
     */
    public final static String SERVICE_CODE_DELIVERY_NOTICE = "FOP_PUSH_FIS_DELIVERY_NOTICE";

    /**
     * 接口服务代码 - 状态回传
     */
    public final static String SERVICE_CODE_OPEARTION_UPLOAD = "FOP_RECE_FIS_OPEARTION_UPLOAD";

    /**
     * 接口服务代码 - 图片回传
     */
    public final static String SERVICE_CODE_IMAGE_UPLOAD = "FOP_RECE_FIS_IMAGE_UPLOAD";

    /**
     * 操作人电话，用于同步工单完成/预约接口中的请求参数
     */
    public final static String OPERATOR_PHONE = "4000238888";

    /**
     * 师傅电话，用于同步派单接口中的请求参数
     */
    public final static String MASTER_PHONE = "13350300176";

    /**
     * 结果码 - 统一接入平台校验成功，调用后端服务成功；
     * 注意：不代表后端业务处理成功，实际业务处理结果，需要查看响应属性apiResultData中的详细结果
     */
    public final static String RESULT_CODE_SUCCESS = "A1000";

    /**
     * 结果码 - 必传参数不可为空
     */
    public final static String RESULT_CODE_PARAM_ERROR = "A1001";

    /**
     * 结果码 - 请求时效已过期
     */
    public final static String RESULT_CODE_TIMEOUT = "A1002";

    /**
     * 结果码 - IP无效
     */
    public final static String RESULT_CODE_INVALID_IP = "A1003";

    /**
     * 结果码 - 无对应服务权限
     */
    public final static String RESULT_CODE_INVALID_PRIVILEGE = "A1004";

    /**
     * 结果码 - 流量受控
     */
    public final static String RESULT_CODE_LIMIT_FLOW = "A1005";

    /**
     * 结果码 - 数字签名无效
     */
    public final static String RESULT_CODE_INVALID_SIGN = "A1006";

    /**
     * 结果码 - 重复请求
     */
    public final static String RESULT_CODE_REQUEST_REPEAT = "A1007";

    /**
     * 结果码 - 数据解密失败
     */
    public final static String RESULT_CODE_DECRYPT_FAILED = "A1008";

    /**
     * 结果码 - 目标服务异常或不可达
     */
    public final static String RESULT_CODE_SERVICE_ERROR = "A1009";

    /**
     * 结果码 - 系统异常
     */
    public final static String RESULT_CODE_SYSTEM_ERROR = "A1099";

    /**
     * 订单状态回传码 - 派单
     */
    public final static int NOTIFY_CODE_DISTRIBUTE = 1;

    /**
     * 订单状态回传码 - 完成
     */
    public final static int NOTIFY_CODE_COMPLETE = 3;

    /**
     * 订单状态回传码 - 提货
     */
    public final static int NOTIFY_CODE_PICKUP = 9;

    /**
     * 订单状态回传码 - 预约成功
     */
    public final static int NOTIFY_CODE_DUTY_SUCCESS = 10;

    /**
     * 订单状态回传码 - 核销
     */
    public final static int NOTIFY_CODE_VERIFY = 11;

    /**
     * 订单状态回传码 - 安装异常
     */
    public final static int NOTIFY_CODE_INSTALL_FAILED = 13;

    /**
     * 订单状态回传码 - 预约失败
     */
    public final static int NOTIFY_CODE_DUTY_FAILED = 14;

    /**
     * 获取结果码的消息
     *
     * @param resultCode
     * @return
     */
    public static String getResultCodeMsg(String resultCode) {

        switch (resultCode) {
            case  RESULT_CODE_SUCCESS:
                return "调用服务成功";
            case RESULT_CODE_PARAM_ERROR:
                return "必传参数为空";
            case RESULT_CODE_TIMEOUT:
                return "请求时效已过期";
            case RESULT_CODE_INVALID_IP:
                return "IP无效";
            case RESULT_CODE_INVALID_PRIVILEGE:
                return "无对应服务权限";
            case RESULT_CODE_LIMIT_FLOW:
                return "流量受控";
            case RESULT_CODE_INVALID_SIGN:
                return "数字签名无效";
            case RESULT_CODE_REQUEST_REPEAT:
                return "重复请求";
            case RESULT_CODE_DECRYPT_FAILED:
                return "数据解密失败";
            case RESULT_CODE_SERVICE_ERROR:
                return "目标服务异常或不可达";
            case RESULT_CODE_SYSTEM_ERROR:
                return "系统异常";
        }

        return "未知的错误码";
    }

    /**
     * 根据操作码获取操作描述
     *
     * @param code
     * @return
     */
    public static String getOperateteContentByCode(int code) {

        switch (code) {
            case NOTIFY_CODE_DISTRIBUTE:
                return "分配安装师傅";
            case NOTIFY_CODE_COMPLETE:
                return "完工";
            case NOTIFY_CODE_PICKUP:
                return "提货";
            case NOTIFY_CODE_DUTY_SUCCESS:
                return "预约成功";
            case NOTIFY_CODE_VERIFY:
                return "核销";
            case NOTIFY_CODE_INSTALL_FAILED:
                return "安装异常";
            case NOTIFY_CODE_DUTY_FAILED:
                return "预约失败";
        }

        return "";
    }

    @NacosValue(value="${shunfeng.api.powerOn:false}", autoRefreshed = true)
    public void setPowerOn(boolean powerOn) {
        POWER_ON = powerOn;
    }

    @NacosValue(value="${shunfeng.api.url:https://sfapi.sit.sf-express.com:45273/std/service}", autoRefreshed = true)
    public void setApiUrl(String apiUrl) {
        API_URL = apiUrl;
    }

    @NacosValue(value="${shunfeng.image.url:http://scs-api-gw.intsit.sfdc.com.cn:1080/hinplusService/routerPic/imageUpload}", autoRefreshed = true)
    public void setImageUrl(String imageUrl) {
        IMAGE_URL = imageUrl;
    }

    @NacosValue(value="${shunfeng.app.partnerId:fop_test}", autoRefreshed = true)
    public void setPartnerId(String partnerId) {
        PARTNER_ID = partnerId;
    }

    @NacosValue(value="${shunfeng.app.key:2Z7YPBNG2CKKBV17}", autoRefreshed = true)
    public void setMd5Key(String md5Key) {
        MD5_KEY = md5Key;
    }

    @NacosValue(value="${shunfeng.image.clientCode:FOP_JDD516}", autoRefreshed = true)
    public void setClientCode(String clientCode) {
        CLIENT_CODE = clientCode;
    }

    @NacosValue(value="${shunfeng.image.md5Key:4PqXaZMkyHHZpbN9}", autoRefreshed = true)
    public void setImageMd5Key(String md5Key) {
        IMAGE_MD5_KEY = md5Key;
    }
}
